import React from 'react' 

function Total({cart}) {
    return <span>总价：{cart.reduce((sum,a)=>{
        return sum + a.price * a.count
    },0)}</span>
}
class Cart extends React.Component{
    render(){
        return <div>
            统计名单
            <table border="1">
                <tbody>
                    <tr>
                        <th>名字</th><th>价格</th><th>数量</th><th>统计</th>
                    </tr>               
                    {this.props.data.map(good=>{
                        return <tr key={good.text}>
                            <td>{good.text}</td><td>{good.price}</td><td>{good.count}</td><td>{good.price * good.count}</td>
                        </tr>
                    })}        
                </tbody>         
            </table>	
            <Total cart={this.props.data}/>
        </div>
    }
}

export default Cart